package com.zxw.mallafter.common;

import com.alibaba.fastjson2.JSON;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

public class Tojson {
    public static void writeJson(HttpServletResponse resp, Map<String,Object> map) {
        String json= JSON.toJSONString(map);
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter writer = null;
        try {
            writer = resp.getWriter();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        writer.print(json);
        writer.flush();

    }


}
